<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.google.appengine.api.users.User" %>
<%@ page import="com.google.appengine.api.users.UserService" %>
<%@ page import="com.google.appengine.api.users.UserServiceFactory" %>
<%@ page import="java.util.List" %>
<%@ page import="javax.jdo.PersistenceManager" %>
<%@ page import="rahcir.Shop" %>
<%@ page import="rahcir.PMF" %>

<html>
  <body>

<%
    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();
    if (user != null) {
%>
<p>Hello, <%= user.getNickname() %>! (You can
<a href="<%= userService.createLogoutURL(request.getRequestURI()) %>">sign out</a>.)</p>
<%
    } else {
%>
<p>Hello!
<a href="<%= userService.createLoginURL(request.getRequestURI()) %>">Sign in</a>
to include your name with greetings you post.</p>
<%
    }
%>

   <hr>Shop List</hr>

<%
    PersistenceManager pm = PMF.get().getPersistenceManager();
    String query = "select from " + Shop.class.getName();
    List<Shop> shops = (List<Shop>) pm.newQuery(query).execute();
    if (shops.isEmpty()) {
%>
	<p>no shops.</p>
<%
    } else {
        for (Shop s : shops) {
%>
<div><a href="/infoShop.jsp?id=<%=s.getId() %>">
<%= s.getShopname() %></a></div>
<%
        }
    }
    pm.close();
%>

	<hr>New Shop</hr>

    <form action="/rahcir" method="post">
      <div>Shop Name:<input type="text" name="shopname"></input></div>
      <div>Comment:<textarea name="comment" rows="3" cols="60"></textarea></div>
      <div>Address:<input type="text" name="address"></input></div>
      <div>Map URL(paste from Google Map):<input type="text" name="mapurl"></input></div>
      <div><input type="hidden" name="type" value="registShop"></input></div>      
      <div><input type="submit" value="New Shop Register" /></div>
    </form>

  </body>
</html>